package com.blue.bluecode;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;


public class SwitchActivity extends Activity {

    private Switch switchButton;
    private TextView tvSwitchStatus;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_switch);
        getActionBar().setDisplayHomeAsUpEnabled(true);


        switchButton = (Switch) findViewById(R.id.switchButton);
        tvSwitchStatus = (TextView) findViewById(R.id.tvSwitchStatus);
        switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                String str = null;
                if(b){
                    str = (String) switchButton.getTextOn();
                }else{
                    str = (String) switchButton.getTextOff();
                }
                tvSwitchStatus.setText(str);
            }
        });

    }


}
